/**
 * Created by Administrator on 2016/1/27.
 */



function convertStr(data){
    if (data == "" || data == null || data== undefined) {
        return "-";
    } else {
        return data;
    }
}


function showDialog(obj){
    if("add" == obj){
        $(".PopupTitle").html("新建用户信息");
        $("#add").modal("show");
    }else{
        $(".PopupTitle").html("修改用户信息");
        $("#add").modal("show");
    }

}


function afterClickTrackPointTab(){
    getTrackPointList();//获取list列表
}


/*导出excl*/
function exportempUse(){
    var data_=$("#empUseForm").serializeFormJSON();
    var p=json2UrlParam(data_);
    location.href=p_path+"/eqpt/equipment/empUse/exportEmpUse.json?"+p;
}
/*条件查询*/
function queryEmpUse(){
    var code=$("#empUseForm").validationEngine("validate");//验证表单
    if(!code){
        return;
    }
    var data_=$("#empUseForm").serializeFormJSON();/*序列化json*/
    attr(data);
    $("#empUse").selectDataAfterSetParm(data_);/*查询数据设置参数*/
}
function delEmpUse(id){
    if (!confirm("是否确定删除?")){
        return;
    }
    $().invoke(
        p_path+"/eqpt/equipment/EmpUse/delEmpUse.json",
        {"id":id},
        [function(m,r){
            if (r=='success'){
                $("#empUse").refresh();
            }
        },function(m,r){
            alert(r);
        }]
    )

}
function delCrossOver(id){
    if (!confirm("是否确定删除?")){
        return;
    }
    $().invoke(
        p_path+"/eqpt/equipment/empUse/delEmpUse.json",
        {"id":id},
        [function(m,r){
            if (r=='success'){
                $("#empUse").refresh();
            }
        },function(m,r){
            alert(r);
        }]
    )

}




function getCrossOverList(){
    var col=[
        /* {title:tableOpt.getCheckBox(null),name:"ID",width:"5%",align:"center",format:function(json){return tableOpt.getCheckBox(json.ID)}},*/
         {title:checkHtml(),name:"SHORT_NAME",width:"5%",align:"center",format:checkHtml},
        {title:"设备编号",name:"customNumber",width:"17%",align:"center"},
        {title:"型号",name:"modelNumber",width:"17%",align:"center"},
       /* {title:"领用单位",name:"uniqueCide",width:"17%",align:"center"},*/
        {title:"领用人",name:"userName",width:"17%",align:"center"},
        {title:"联系电话",name:"userPhone",width:"17%",align:"center"},
        {title:"领用日期",name:"startDateStr",width:"17%",align:"center"},
        {title:"预计归还日期",name:"endDateStr",width:"17%",align:"center"},
//        {title:"有效时间",name:"state",width:"17%",align:"center"},
        {title:"编辑 删除",name:"id",width:"80",align:"center",format:dataEdit}
//        {title:"删除",name:"id",width:"5%",align:"center",format:dataDeatil}
        /*{title:"删除",name:"",width:"5%",align:"center",format:dataDel}*/
    ];
    
    new page(".sj-main",col);
  
}

//选择框
function checkHtml(data){
	var id=null;
	if(data != undefined)
	{
		id=data["ID_"];
	}
	return  '<span class="table-ck"><span class="check-box selected " '+(id!=null?"id='"+id+"' item=''":"base=''")+' ><i></i></span></span>';
}
function empUseRowClick(data,obj,orderNum){
    try {
        var eventTarget_ = event.target || event.srcElement;
        if (eventTarget_ != null && eventTarget_ != document&& eventTarget_.tagName=="EM") {
            if ($(eventTarget_).hasClass("delet2")) {
                return;
            }
        }
    } catch (e) {
        console.log(e)
    }
    return false;
}


function dataDeatil(json){
    var h="<li class=\"w12-4-3-1 no-right\" style='list-style: none;'>" +
        "<em  class=\"delet2 del\" tag='delurl'></em></li>";
    return h;
}
function dataEdit(json){
    var h="<li class='w15 no-right' style='list-style-type:none;position:relative;'><em  class='edit0 new  edit'  modal='#add' title='编辑领用信息' url='"+p_path + "/eqpt/equipment/empUse/updateEmpUse.json"+"'  class=\"edit_00\" ></em> <em  class=\"delet2 new del\" tag='delurl'></em></li>" ;
    return h;
}



//查询--成功
function queryEmpUse(){
    var customNumber = $.trim($("#searchCustomNumber").val());
    var modelNumber = $.trim($("#searchModelNumber").val());
    var uniqueCide = $.trim($("#searchUniqueCide").val());
    var buyDate = $.trim($("#searchStartDate").val())
    var buyDateEnd=$.trim($("#searchStartDate1").val());
    var state = $("#searchstateDiv").children().attr("id") == "state" ? "" : $("#searchstateDiv").children().attr("id");
   
    var data = {"customNumber":customNumber,"modelNumber":modelNumber,"uniqueCide":uniqueCide,"beginbuyDate":buyDate,"endbuyDate":buyDateEnd,"state":state}
    console.log(data);
    $('#empUse').selectDataAfterSetParm(data);
}

$(function(){
    getCrossOverList();
})


function empUseCilck(data,obj,orderNum){
    try{
        var eventTarget_= event.target || event.srcElement;
        if (eventTarget_ != null && eventTarget_ != document&& eventTarget_.tagName=="EM") {
            if ($(eventTarget_).hasClass("delet2")) {
                return;
            }
        }
    } catch (e) {
        console.log(e)
    }

    var t=$("#trackPoint"+orderNum,$("#trackPoint"));
    $("td",t).html(showTrackPointUl(data));
    t.fadeToggle();
    return false;

}

/*新增*/
function addEmpUse(){
    var customNumber = $.trim($("#customNumber").val());
    var modelNumber = $.trim($("#modelNumber").val());
    var uniqueCide = $.trim($("#uniqueCide").val());
    /*  var stata = $("#stateDiv").children().text();*/
    var buyDate = $.trim($("#buyDate").val());
    var remark = $.trim($("#remark").val());

    if("" !== customNumber ){
        alert("请输入设备编号");
        return false;
    }else if("" !== modelNumber ){
        alert("请输入设备型号");
        return false;
        /*  }else if("服务中" != state && "未服务" != state){
         alert("请选择设备状态");
         return false;*/
    }else if("" !== uniqueCide ){
        alert("请输入唯一标识码");
        return false;
    }else if("" !== buyDate ){
        alert("请输入购买时间");
        return false;
    }else{
        var data = {"customNumber":customNumber,"modelNumber":modelNumber,"uniqueCide":uniqueCide,"buyDate":buyDate}
        $().invoke(p_path + "/eqpt/equipment/empUse/addEmpUse.json",data,[function(m,r){
            if(1==r){
                alert("保存成功");
                $("#xjsb").modal("hide");
                $("#empUse").refresh();
//				window.location.href = pagePath + "/settings/user/getUserManagerIndex.html";
            }
        }]);
    }
}


function queryCrossOver(){
    var vR=$("#empUseQueryForm").validationEngine("validate");
    if (!vR){
        return;
    }
    var data_=$("#empUseQueryForm").serializeFormJSON();
    $("#empUse").selectDataAfterSetParm(data_);
}
/*编辑更新*/
function  updateempUse(id){
    $().invoke(
        p_path+"eqpt/updateEmpUse.json",{"id":id,"customNumber":customNumber,"modelNumber":modelNumber,"uniqueCide":uniqueCide,"buyDate":buyDate,"state":state,"updateRemark":updateRemark},[function(m,r){

            $("empUse").refresh();

        }]
    )

}

/**
 * 初始化新增弹出框
 */
function initView(obj){
    var obj = $(obj);
    obj.find("input").val("");
    obj.find("textarea").val("");
    $("#StateDiv").children().text("性别");
    /* $("#companyDiv").children().text("请选择公司");
     $("#departmentDiv").children().text("请选择部门");
     $("#positionDiv").children().text("请选择岗位");*/
}
/*导出*/
function exportempUse(){
    //var juliStart=nvl_($("#juliStart").val());
    //var juliEnd=nvl_($("#juliEnd").val());
    var data_=$("#empUseForm").serializeFormJSON();
    var p=json2UrlParam(data_);
    location.href=p_path+"/eqpt/exportempUse.json?"+p;
}
